package example.utils;

import java.sql.*;

public class JDBCUtils {
    public static Connection getConnection()throws SQLException
            ,ClassNotFoundException{
    Class.forName("com.mysql.cj.jdbc.Driver");
    String url="jdbc:mysql://47.111.186.126:3306/jdbc"+
            "?useSSL=false&&allowPublicKeyRetrieval=true&serverTimezone=UTC";
    String username="root";
    String password="123456";
    Connection conn= DriverManager.getConnection(url,username
            ,password);
    return  conn;
    }
    public static void release(Statement statement,Connection connection){
        if (statement!=null){
            try {
                statement.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
            statement = null;
        }
        if (connection!=null){
            try {
                connection.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
            connection = null;
        }
    }
    public static void release(ResultSet resultSet,Statement statement,
                               Connection connection){
        if (resultSet!=null){
            try {
                resultSet.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
            resultSet = null;
        }
        release(statement,connection);
    }
}
